<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!--  第一步引入 vue.js -->
    <script src="js/vue.js"></script>
    <script src="js/vue-router.js"></script>
    <style>
        .r {
            height: 100px;
            width: 200px;
            background-color: red;
        }

        .b {
            height: 100px;
            width: 200px;
            background-color: blue;
        }
    </style>
</head>
<body>

<div id="app">
<!--     注意router-link 中的to 需要绑定属性 ，所以变成了 :to-->
    <router-link :to="{ name: 'user', params: { userId: 123 }}">命名式路由user </router-link>
    <router-link :to="{ name: 'account', params: { accountId: 123 }}">命名式路由account </router-link>

    <router-view></router-view>
</div>

<template id="login">
    <div class="r">
        <h1>这是 登录组件</h1>
    </div>
</template>

<template id="register">
    <div class="b">
        <h1>这是 注册组件</h1>
    </div>
</template>

<template id="account">
    <div>

        <p>这个是 account 路由组件</p>
    </div>

</template>

<script>

    var login = {
        template: "#login",
        created(){
            console.log("login  的参数"+this.$route.params.userId)
        }

    }

    var register = {
        template: "#register",
    }
    var account = {
        template: "#account",
        created(){
            console.log("account  的参数"+this.$route.params.accountId)
        }
    }
    const router = new VueRouter({
        routes: [
            {
                path: "/user/:userId",
                component: login,// 路由嵌套路由
                name:"user"
            },

            {
                path: "/account/:accountId",
                component: account,// 路由嵌套路由
                name:"account"
            },
        ]
    })
    var vm = new Vue({
        el: "#app",
        data: {
            msg: "欢迎走进 Vue的 入门学习 ，joker  欢迎你",
        },
        router

    });


</script>

</body>
</html>